package com.neusoft.clouduserfeign.controller;

import com.neusoft.clouduserfeign.dto.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 负载均衡信息控制器
 * 用于查看服务实例信息
 */
@RestController
@RequestMapping("/loadbalancer")
public class LoadBalancerInfoController {
    
    @Autowired
    private DiscoveryClient discoveryClient;
    
    /**
     * 获取所有服务列表
     */
    @GetMapping("/services")
    public Result<List<String>> getServices() {
        List<String> services = discoveryClient.getServices();
        return Result.success("获取服务列表成功", services);
    }
    
    /**
     * 获取用户服务的所有实例
     */
    @GetMapping("/user-service-instances")
    public Result<List<ServiceInstance>> getUserServiceInstances() {
        List<ServiceInstance> instances = discoveryClient.getInstances("cloud-user-service");
        return Result.success("获取用户服务实例成功", instances);
    }
    
    /**
     * 获取当前服务信息
     */
    @GetMapping("/current-service")
    public Result<String> getCurrentService() {
        return Result.success("当前服务信息", "cloud-user-feign 负载均衡客户端");
    }
}
